﻿using System;
using System.Collections.Generic;

namespace Solution
{
    public class Class1
    {
        public int LengthOfLongestSubstring(string s)
        {
            int left = 0;
            int maxLength = 0;
            if (s.Length == 0 || s.Length == 1)
                return s.Length;

            Dictionary<char, int> dict = new Dictionary<char, int>();
            for (int i = 0; i < s.Length; i++)
            {
                if (dict.ContainsKey(s[i]))
                {
                    maxLength = i - left > maxLength ? i - left : maxLength;
                    if(left<=dict[s[i]]){
                        left = dict[s[i]]+1;
                    }
                    Console.WriteLine($"i:{i} left:{left} char:{s[i]} repeat:{dict[s[i]]} maxLenght:{maxLength}");
                    for(int j = 0;j<left;j++){
dict.Remove(s[j]);
                    }
                    
                }
                dict.Add(s[i], i);
            }
            Console.WriteLine($"length-left:{s.Length - left} maxLenght:{maxLength}");

            return s.Length - left > maxLength ? s.Length - left : maxLength;
        }
    }
}
